package com.itany.controller;


import com.github.pagehelper.PageInfo;
import com.itany.exception.BookException;
import com.itany.pojo.Book;
import com.itany.service.BookService;
import com.itany.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;


    @RequestMapping("/findAll")
    @ResponseBody
    public Map<String,Object>findAll(@RequestParam(defaultValue ="1")String page,
                                     @RequestParam(defaultValue ="10")String rows,Book book){
        System.out.println("~~~进入findAll");
        PageInfo<Book> pageInfo=bookService.findAll(page,rows,book);
        Map<String,Object> map=new HashMap<>();
        map.put("total",pageInfo.getTotal());
        map.put("rows",pageInfo.getList());
        return map;
    }


    @RequestMapping("/modifyStatus")
    @ResponseBody
    public AjaxResult modifyStatus(Book book){
        try {
            bookService.modifyBookStatus(book);
        } catch (BookException e) {
            e.printStackTrace();
        }
        return AjaxResult.isOk("修改成功");

    }






}
